package com.boss.salary.service.impl;

import com.boss.common.entity.PageDTO;
import com.boss.common.util.DateUtils;
import com.boss.framework.dto.PaginationDTO;
import com.boss.salary.constant.SystemDictConstant;
import com.boss.salary.dao.IAgencyExtDao;
import com.boss.salary.entity.AgencyExt;
import com.boss.salary.entity.AgencyInfo;
import com.boss.salary.service.IAgencyExtService;
import com.boss.sys.utils.SysUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AgencyExtServiceImpl implements IAgencyExtService {

    /**
     * 引入日志框架常量
     */
    private final static Logger logger = LoggerFactory.getLogger(AgencyExtServiceImpl.class);

    @Autowired
    private IAgencyExtDao agencyExtDao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertAgencyExt(AgencyExt agencyExt) {
        agencyExt.setId(SysUtils.generateGuid());
        agencyExt.setCreateTime(String.valueOf(DateUtils.getCurrentTimeStamp()));
        agencyExt.setUpdateTime(String.valueOf(DateUtils.getCurrentTimeStamp()));
        agencyExt.setIsDeleted(SystemDictConstant.IS_FALSE);
        agencyExtDao.insertAgencyExt(agencyExt);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAgencyExt(String id) {
        agencyExtDao.deleteAgencyExt(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateAgencyExt(AgencyExt agencyExt) {
        agencyExt.setUpdateTime(String.valueOf(DateUtils.getCurrentTimeStamp()));
        agencyExtDao.updateAgencyExt(agencyExt);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateAgencyExtBank(AgencyExt agencyExt) {
        agencyExt.setUpdateTime(String.valueOf(DateUtils.getCurrentTimeStamp()));
        agencyExtDao.updateAgencyExtBank(agencyExt);
    }

    @Override
    public PageDTO<AgencyExt> queryAgencyExtPage(PaginationDTO paginationDTO) {
        List<AgencyExt> agencyExts = agencyExtDao.queryAgencyExtPage(paginationDTO);
        int total = agencyExtDao.queryAgencyExt();
        PageDTO<AgencyExt> pageDTO = new PageDTO<>();
        pageDTO.setRows(agencyExts);
        pageDTO.setTotal(total);
        return pageDTO;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)

    public void submitVerify(List<AgencyInfo> agencyInfoList) {
        for (AgencyInfo agencyInfo : agencyInfoList ) {
            AgencyExt agencyExt = new AgencyExt();
            agencyExt.setAgencyId(agencyInfo.getId());
            agencyExt.setUpdateTime(String.valueOf(DateUtils.getCurrentTimeStamp()));
            agencyExtDao.submitVerify(agencyExt);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void revokeVerify(List<AgencyInfo> agencyInfoList) {
        for (AgencyInfo agencyInfo : agencyInfoList ) {
            AgencyExt agencyExt = new AgencyExt();
            agencyExt.setAgencyId(agencyInfo.getId());
            agencyExt.setUpdateTime(String.valueOf(DateUtils.getCurrentTimeStamp()));
            agencyExtDao.revokeVerify(agencyExt);
        }
    }
}
